commonlibsse_ng\skse\interfaces/
query.rs

1// C++ Original code
2// - ref: https://github.com/SARDONYX-forks/CommonLibVR/blob/ng/include/SKSE/Interfaces.h
3// - ref: https://github.com/SARDONYX-forks/CommonLibVR/blob/ng/src/SKSE/Interfaces.cpp
4// SPDX-FileCopyrightText: (C) 2018 Ryan-rsm-McKenzie
5// SPDX-License-Identifier: MIT
6//
7// SPDX-FileCopyrightText: (C) 2025 SARDONYX
8// SPDX-License-Identifier: Apache-2.0 OR MIT
9
10use crate::{rel::version::Version, skse::impls::stab::SKSEInterface};
11
12/// Provides an interface to query various version-related information.
13///
14/// This trait is designed to be implemented for structures that contain
15/// versioning information, such as `SKSEInterface`. It allows querying the
16/// editor version, runtime version, and SKSE version, as well as determining
17/// whether the interface is running in an editor environment.
18pub trait QueryInterface {
19    /// Returns the editor version as a `u32`.
20    fn editor_version(&self) -> u32;
21
22    /// Returns `true` if the interface is running in the editor, otherwise `false`.
23    fn is_editor(&self) -> bool;
24
25    /// Returns the runtime version as a `Version` struct.
26    fn runtime_version(&self) -> Version;
27
28    /// Returns the SKSE (Skyrim Script Extender) version as a `u32`.
29    fn skse_version(&self) -> u32;
30}
31
32impl QueryInterface for SKSEInterface {
33    #[inline]
34    fn editor_version(&self) -> u32 {
35        self.editorVersion
36    }
37
38    #[inline]
39    fn is_editor(&self) -> bool {
40        self.isEditor != 0
41    }
42
43    #[inline]
44    fn runtime_version(&self) -> Version {
45        let packed = self.runtimeVersion;
46        let major = ((packed & 0xFF000000) >> 24) as u16;
47        let minor = ((packed & 0x00FF0000) >> 16) as u16;
48        let revision = ((packed & 0x0000FFF0) >> 4) as u16;
49        let build = (packed & 0x0000000F) as u16;
50        Version::new(major, minor, revision, build)
51    }
52
53    #[inline]
54    fn skse_version(&self) -> u32 {
55        self.skseVersion
56    }
57}